{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "timed out\n"
     ]
    }
   ],
   "source": [
    "# Tushare get data\n",
    "import tushare as ts\n",
    "\n",
    "# data = ts.get_h_data('sh',start='2012-04-10',end='2013-04-10')\n",
    "# print data\n",
    "\n",
    "\n",
    "sh = ts.get_hist_data('sh')\n",
    "\n",
    "print data\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# get tick data of single stock on specific date\n",
    "# df = ts.get_tick_data('600848',date='2014-12-22')\n",
    "# df['Date'] = '2014-12-22'\n",
    "# json.loads(df.to_json(orient='records'))\n",
    "\n",
    "# get all concepts, very slow\n",
    "# concepts = ts.get_concept_classified()\n",
    "# concepts\n",
    "\n",
    "#sh = ts.get_hist_data('sh')  #获取上证指数k线数据，其它参数与个股一致，下同\n",
    "\n",
    "#json.loads(sh.to_json(orient='records'))\n",
    "#json.loads(sh.to_json(orient='split'))\n",
    "# ts.get_hist_data('sz'）#获取深圳成指k线数据\n",
    "# ts.get_hist_data('hs300'）#获取沪深300指数k线数据\n",
    "# ts.get_hist_data('sz50'）#获取上证50指数k线数据\n",
    "# ts.get_hist_data('zxb'）#获取中小板指数k线数据\n",
    "# ts.get_hist_data('cyb'）#获取创业板指数k线数据\n",
    "\n",
    "# data = ts.get_hist_data('600848',start='2015-01-05',end='2015-01-09')\n",
    "# data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Tushare get data\n",
    "import tushare as ts\n",
    "import json\n",
    "\n",
    "# get tick data of single stock on specific date\n",
    "# df = ts.get_tick_data('600848',date='2014-12-22')\n",
    "# df['Date'] = '2014-12-22'\n",
    "# json.loads(df.to_json(orient='records'))\n",
    "\n",
    "# get all concepts, very slow\n",
    "# concepts = ts.get_concept_classified()\n",
    "# concepts\n",
    "\n",
    "sh = ts.get_hist_data('sh')  #获取上证指数k线数据，其它参数与个股一致，下同\n",
    "sh\n",
    "\n",
    "data =json.loads(sh.reset_index().to_json(orient='records'))\n",
    "data\n",
    "#sh.reset_index() # put index to normal column\n",
    "\n",
    "#json.loads(sh.to_json(orient='split'))\n",
    "# ts.get_hist_data('sz'）#获取深圳成指k线数据\n",
    "# ts.get_hist_data('hs300'）#获取沪深300指数k线数据\n",
    "# ts.get_hist_data('sz50'）#获取上证50指数k线数据\n",
    "# ts.get_hist_data('zxb'）#获取中小板指数k线数据\n",
    "# ts.get_hist_data('cyb'）#获取创业板指数k线数据\n",
    "\n",
    "# data = ts.get_h_data('sh',start='2000-04-10',end='2001-04-10')\n",
    "# data"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
